package datastream.api.operator.one;

import datastream.api.operator.one.source.user.UserSource;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import datastream.api.operator.one.pojo.user.InputModel;

// 过滤 age>=50 岁的数据
public class Filter {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);

        DataStreamSource<InputModel> source = env.addSource(new UserSource());

        SingleOutputStreamOperator<InputModel> filter = source.filter(new FilterFunction<InputModel>() {
            @Override
            public boolean filter(InputModel value) throws Exception {
                return value.getAge() < 50;
            }
        });

        DataStreamSink<InputModel> sink = filter.print();

        env.execute();
    }
}
